﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using AutoMapper;

namespace DAO
{
    public class CT_PhieuTraRepository
    {
        public static CT_PhieuTraDTO CreateCTPhieuTraDTOFromCTPhieuTraEF(CT_PHIEU_TRA chiTietPT)
        {
            CT_PhieuTraDTO chiTietDTO = new CT_PhieuTraDTO();
            Mapper.CreateMap<CT_PHIEU_TRA, CT_PhieuTraDTO>();
            chiTietDTO = Mapper.Map<CT_PHIEU_TRA, CT_PhieuTraDTO>(chiTietPT);
            return chiTietDTO;
        }
        public static CT_PHIEU_TRA CreateCTPhieuTraEFFromCTPhieuTraDTO(CT_PhieuTraDTO chiTietDTO)
        {
            CT_PHIEU_TRA chiTietPT = new CT_PHIEU_TRA();
            Mapper.CreateMap<CT_PhieuTraDTO, CT_PHIEU_TRA>();
            chiTietPT = Mapper.Map<CT_PhieuTraDTO, CT_PHIEU_TRA>(chiTietDTO);
            return chiTietPT;
        }

        public void ThemCTPhieuTra(CT_PhieuTraDTO chiTietDTO)
        {
            try
            {
                QLTVEntities context = new QLTVEntities();
                CT_PHIEU_TRA chiTietPT = new CT_PHIEU_TRA();
                chiTietPT = CreateCTPhieuTraEFFromCTPhieuTraDTO(chiTietDTO);

                context.AddToCT_PHIEU_TRAList(chiTietPT);
                context.SaveChanges();

            }
            catch (System.Exception)
            {

            }
        }
    }
}
